<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js 冒泡排序</title>
</head>
<body>
<script>
    //冒泡排序
    var array = [23, 5, 75, 467, 78,87,8,31,548,45,154,65,485,3448,124];

    for (var i = 0; i < array.length - 1; i++) {

        for (var j = 0; j < array.length - i - 1; j++) {

            if (array[j] > array[j + 1]) {

                var temp = array[j + 1];//temp = 4;给temp赋上了第二个值

                array[j + 1] = array[j];//array[j + 1] = 5;把第二个值改为5

                array[j] = temp;//array[j] = 4;第一个值改为temp，temp = 4，所以
                //最终 两个值交换了位置
            }
        }
    }
    console.log(array);
</script>
</body>
</html>